package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Draw;
import com.ruoyi.system.service.IDrawService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 画展作品Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@Controller
@RequestMapping("/system/draw")
public class DrawController extends BaseController
{
    private String prefix = "system/draw";

    @Autowired
    private IDrawService drawService;

    @RequiresPermissions("system:draw:view")
    @GetMapping()
    public String draw()
    {
        return prefix + "/draw";
    }

    /**
     * 查询画展作品列表
     */
    @RequiresPermissions("system:draw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Draw draw)
    {
        startPage();
        List<Draw> list = drawService.selectDrawList(draw);
        return getDataTable(list);
    }

    /**
     * 导出画展作品列表
     */
    @RequiresPermissions("system:draw:export")
    @Log(title = "画展作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Draw draw)
    {
        List<Draw> list = drawService.selectDrawList(draw);
        ExcelUtil<Draw> util = new ExcelUtil<Draw>(Draw.class);
        return util.exportExcel(list, "画展作品数据");
    }

    /**
     * 新增画展作品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存画展作品
     */
    @RequiresPermissions("system:draw:add")
    @Log(title = "画展作品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Draw draw)
    {
        return toAjax(drawService.insertDraw(draw));
    }

    /**
     * 修改画展作品
     */
    @RequiresPermissions("system:draw:edit")
    @GetMapping("/edit/{drawId}")
    public String edit(@PathVariable("drawId") Long drawId, ModelMap mmap)
    {
        Draw draw = drawService.selectDrawByDrawId(drawId);
        mmap.put("draw", draw);
        return prefix + "/edit";
    }

    /**
     * 修改保存画展作品
     */
    @RequiresPermissions("system:draw:edit")
    @Log(title = "画展作品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Draw draw)
    {
        return toAjax(drawService.updateDraw(draw));
    }

    /**
     * 删除画展作品
     */
    @RequiresPermissions("system:draw:remove")
    @Log(title = "画展作品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(drawService.deleteDrawByDrawIds(ids));
    }
}
